package ThreadDemo;
/*当一个线程读取一个线程修改同一个变量和的时候
* 读取变量的线程无法感知另一个线程对该变量的修改*/

import java.util.Scanner;

class A18{
     int a=0;
    public void increase(){
        a++;
    }
}

public class ThreadDemo18 {
    public static void main(String[] args) {
        A18 a18=new A18();
        Thread t1 = new Thread() {
            @Override
            public void run() {
                while(a18.a==0) {

                }
                System.out.println("循环结束");
            }
        };
        t1.start();
        Thread t2 = new Thread() {
            @Override
            public void run() {
                Scanner sc=new Scanner(System.in);
                System.out.println("请输入一个整数：");
                a18.a=sc.nextInt();
            }
        };
        t2.start();
    }
}
